package com.framework.res;


import com.softcomputo.commons.exception.ValidacionRuntimeException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;


public class LineStringToList {
	
  public static List<String> toList(String in){
		  return toList(in, ",");  
  }	
	
  public static List<String> toList(String in, String separator){
	  while (in.contains(",,")) {in = in.replace(",,", ",@null@,");}
//	  System.out.println(in);
	  StringTokenizer tokenizer = new StringTokenizer(in, separator);
	  List<String>  list = null;
	  while (tokenizer.hasMoreTokens()) { 
		  if(list == null)
			  list = new ArrayList<String>();
		  String in_ = tokenizer.nextToken();
//		  System.out.println(in_);
		  list.add(in_.replace("@null@", "").trim());  
	  }
	  return list;
  }
  
  public static Timestamp convertTo(String time){
	   if(time.matches("\\d{2}/\\d{2}/\\d{4}")){ 
		   String[] timeRes =  time.trim().split("/");
		   String yyyy = timeRes[2];
		   String MM = timeRes[1];
		   String dd = timeRes[0];
		   String fechaString = "yyyy-MM-dd 00:00:00".replace("yyyy", yyyy)
		   .replace("MM", MM)
		   .replace("dd", dd);
		   return Timestamp.valueOf(fechaString);
	   }
	   throw new ValidacionRuntimeException("Formato de fecha incorreto: " + time); 
  }
}
